<?php

/*
 * This file is part of PHP CS Fixer.
 * (c) kcloze <pei.greet@qq.com>
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

define('SWOOLE_XYH_PATH', __DIR__ );

date_default_timezone_set('Asia/Shanghai');

require SWOOLE_XYH_PATH . '/Xphp/Kcloze/Loader.php';

use Kcloze\Jobs\JobObject;
use Kcloze\Jobs\Logs;
use Kcloze\Jobs\Queue\BaseTopicQueue;
use Kcloze\Jobs\Queue\Queue;

$config        = require_once SWOOLE_XYH_PATH . '/config.php';
$logger        = Logs::getLogger($config['logPath'] ?? '', $config['logSaveFileApp'] ?? '');
$queue         = Queue::getQueue($config['job']['queue'], $logger);

$queue->setTopics($config['job']['topics']);

if (!$queue) {
    die("queue object is null\n");
}

//jobs的topic需要在配置文件里面定义，并且一次性注册进去
$topics = $queue->getTopics();
//var_dump($topics); exit;

for ($i = 0; $i < 100000; ++$i) {
    $rand                  = mt_rand(0, 100);
    $delay                 = 0;
    $priority              = BaseTopicQueue::HIGH_LEVEL_1;
    $jobExtras['delay']    = $delay;
    $jobExtras['priority'] = $priority;
    $job                   = new JobObject('MyJob', '\app\index\Controller\JobAction', 'test1', ['测试1', time()], $jobExtras);
    $result                = $queue->push('MyJob', $job, 1, 'json');
  //  var_dump($result);
}
